package cn.wolfcode.cloud.orderserver.service.impl;

import cn.wolfcode.cloud.orderserver.domain.Order;
import cn.wolfcode.cloud.orderserver.service.IOrderService;
import cn.wolfcode.cloud.productapi.domian.Product;
import cn.wolfcode.cloud.productapi.service.ProductFeignApi;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.Date;
import java.util.UUID;

@Service
@Slf4j
public class OrderServiceImpl implements IOrderService {

   /* @Autowired
    private RestTemplate restTemplate;*/

    @Autowired
    private ProductFeignApi productFeignApi;


    @Override
    public Order save(Long userId, Long productId) {
        log.info("订单服务 接受的参数:userId={},productId={}",userId,productId);

        Order order = new Order();
        Product product = productFeignApi.getProduct(productId);
        order.setOrderNo(UUID.randomUUID().toString().replace("-", ""));
        order.setCreateTime(new Date());
        order.setUserId(userId);
        order.setProductName(product.getName());
        order.setProductPrice(product.getPrice());

        log.info("订单服务 响应的参数:{}",order);
        return order;
    }

}